package com.oasistudio.ads.expert.banner;

import android.app.Activity;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

import com.madhouse.android.ads.AdListener;
import com.madhouse.android.ads.AdView;
import com.oasistudio.ads.expert.R;

public class AdViewSmartmad {
	SmartmadAdRequestListener adRequestListener;
	Activity activity;
	public static final String UNION = "smartmad.com";
	public AdViewSmartmad(Activity activity) {
		this.activity = activity;
		this.adRequestListener = new SmartmadAdRequestListener(activity, UNION);

		addSmartMadAd();
	}

	/************************** www.smartmad.com start *************************/
	private void addSmartMadAd() {
		LinearLayout adContainer = (LinearLayout) activity.findViewById(R.id.ads_container);
		adContainer.addView(new TitleBuilder().createTitle(activity, UNION));

		LinearLayout smartMadContainer = new LinearLayout(activity);
		adContainer.addView(smartMadContainer);

		// com.madhouse.android.ads.AdView adview = new
		// com.madhouse.android.ads.AdView(this, null, 0, "1a37ad03ed830c48",
		// 60, 0, 1, true);
		com.madhouse.android.ads.AdView adview = new com.madhouse.android.ads.AdView(activity, null, 0, "90010321", 60,
				0, 1, false);
		adview.setListener(this.adRequestListener);
		smartMadContainer.addView(adview, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
				LayoutParams.WRAP_CONTENT));
	}

	/************************** www.smartmad.com end *************************/

	class SmartmadAdRequestListener extends AbstractAdsExpertAdListener implements AdListener {

		public SmartmadAdRequestListener(Activity activity, String union) {
			super(activity, union);
		}

		@Override
		public void onAdEvent(AdView adView, int event) {
			// TODO Auto-generated method stub
			switch (event) {
			case AdView.EVENT_NEWAD:{
				this.succeed();
				AdHistory.saveAd(UNION, adView);
				break;
			}
			case AdView.EVENT_INVALIDAD:
				this.fail();
				break;
			case AdView.EVENT_INCOMPLETE_PERMISSION:
				this.fail();
				break;
			}
		}

		@Override
		public void onAdFullScreenStatus(boolean arg0) {
			// TODO Auto-generated method stub

		}
	}
}